using System;
using System.Collections;
using System.Data;
using System.Runtime.Serialization;
using System.Reflection;
using System.Xml;
using OutSystems.ObjectKeys;
using OutSystems.RuntimeCommon;
using OutSystems.HubEdition.RuntimePlatform;
using OutSystems.HubEdition.RuntimePlatform.Db;

namespace OutSystems.NssRemotingRadarsAdapter {

	/// <summary>
	/// Record type <code>RCEvento_RRRecord</code> that represents a record of <code>Evento_RR</code>
	/// </summary>
	[Serializable()]
	public partial struct RCEvento_RRRecord: IRecord, ISerializable {
		public static void EnsureInitialized() {}

		/// <summary>
		/// Entity: STEvento_RRStructure
		/// </summary>
		public STEvento_RRStructure ssSTEvento_RR;

		public static implicit operator STEvento_RRStructure(RCEvento_RRRecord r) {
			return r.ssSTEvento_RR;
		}

		public static implicit operator RCEvento_RRRecord(STEvento_RRStructure r) {
			RCEvento_RRRecord res = new RCEvento_RRRecord(null);
			res.ssSTEvento_RR = r;
			return res;
		}


		public BitArray[] GetDefaultOptimizedValues() {
			BitArray[] all = new BitArray[1];
			all[0] = null;
			return all;
		}

		public BitArray[] AllOptimizedAttributes {
			set {
				if(value == null) {
				} else {
					ssSTEvento_RR.OptimizedAttributes = value[0];
				}
			}
			get {
				BitArray[] all = new BitArray[1];
				all[0] = null;
				return all;
			}
		}
		/// <summary>
		/// Comparison Function
		/// </summary>
		/// <param name="a"> First Object</param>
		/// <param name="b"> Second Object</param>
		/// <returns>True if are equal</returns>
		public static bool operator ==(RCEvento_RRRecord a, RCEvento_RRRecord b) {
			if(a.ssSTEvento_RR != b.ssSTEvento_RR) return false;
			return true;
		}

		public static bool operator !=(RCEvento_RRRecord a, RCEvento_RRRecord b) {
			return !(a==b);
		}

		public override bool Equals(object o) {
			if(o.GetType() != typeof(RCEvento_RRRecord)) return false;
			return(this ==(RCEvento_RRRecord) o);
		}

		/// <summary>
		/// Hash Code value
		/// </summary>
		/// <returns>The hash code value</returns>
		public override int GetHashCode() {
			return base.GetHashCode() ^ ssSTEvento_RR.GetHashCode();
		}

		public void GetObjectData(SerializationInfo info, StreamingContext context) {
			Type objInfo = this.GetType();
			FieldInfo[] fields;
			fields = objInfo.GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
			for(int i = 0; i < fields.Length; i++)
			if(fields[i] .FieldType.IsSerializable)
			info.AddValue(fields[i] .Name, fields[i] .GetValue(this));
		}

		public RCEvento_RRRecord(SerializationInfo info, StreamingContext context) {
			ssSTEvento_RR = new STEvento_RRStructure(null);
			Type objInfo = this.GetType();
			FieldInfo[] fields;
			fields = objInfo.GetFields(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
			if(fields[0] .FieldType.IsSerializable)
			ssSTEvento_RR = (STEvento_RRStructure) info.GetValue(fields[0] .Name, fields[0] .FieldType);
		}

		/// <summary>
		/// Read from database
		/// </summary>
		/// <param name="r"> Data reader</param>
		public void ReadDB(IDataReader r) {
			int index = 0;
			ssSTEvento_RR.Read(r, ref index);
		}

		/// <summary>
		/// Read from record
		/// </summary>
		/// <param name="r"> Record</param>
		public void ReadIM(RCEvento_RRRecord r) {
			this = r;
		}

		/// <summary>
		/// Performs a recursive reset
		/// </summary>
		public void RecursiveReset() {
			ssSTEvento_RR.RecursiveReset();
		}

		/// <summary>
		/// Performs an internal recursive reset
		/// </summary>
		public void InternalRecursiveSave() {
			ssSTEvento_RR.InternalRecursiveSave();
		}

		public bool ChangedAttributeGet(GlobalObjectKey key) {
			throw new Exception("Method not Supported");
		}
		public bool OptimizedAttributeGet(GlobalObjectKey key) {
			throw new Exception("Method not Supported");
		}
		/// <summary>
		/// Duplicates the current object
		/// </summary>
		/// <returns>A duplicated instance</returns>
		public IRecord Duplicate() {
			RCEvento_RRRecord t;
			t.ssSTEvento_RR = this.ssSTEvento_RR.Duplicate();
			return t;
		}

		/// <summary>
		/// Default Constructor
		/// </summary>
		public RCEvento_RRRecord(params string[] dummy) {
			ssSTEvento_RR = new STEvento_RRStructure("");
		}

		public void ToXml(Object parent, System.Xml.XmlElement baseElem, String fieldName, int detailLevel) {
			System.Xml.XmlElement recordElem = VarValue.AppendChild(baseElem, "Record");
			if(fieldName != null) VarValue.AppendAttribute(recordElem, "debug.field", fieldName);
			if(detailLevel > 0) {
				ssSTEvento_RR.ToXml(parent, recordElem, "Evento_RR", detailLevel - 1);
			} else {
				VarValue.AppendDeferredEvaluationElement(recordElem);
			}
		}

		public void EvaluateFields(VarValue variable, Object parent, String baseName, String fields) {
			String head = VarValue.GetHead(fields);
			String tail = VarValue.GetTail(fields);
			variable.Found = false;
			if(head == "evento_rr") {
				variable.Value = ssSTEvento_RR;
				variable.SetFieldName("evento_rr");
			}
			if(variable.Found && tail != null) variable.EvaluateFields(parent, head, tail);
		}

		public ISimpleRecord ElementGet(GlobalObjectKey key, int index) {
			if(key.Equals(STEvento_RRStructure.OriginalKey) &&(index == 1)) {
				return ssSTEvento_RR;
			} else {
				throw new Exception("Invalid key or index");
			}
		}
		public void FillFromOther(IRecord other) {
			ssSTEvento_RR.FillFromOther(other.ElementGet(STEvento_RRStructure.OriginalKey, 1));
		}
	} // RCEvento_RRRecord
}
